package com.icode.web.validateController;

import com.icode.core.model.user.User;
import com.icode.core.model.user.UserInfo;
import com.icode.core.shared.SecurityUtil;
import com.icode.service.user.UserService;
import com.icode.web.ajaxValid.UserInfoAjaxValid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created with IntelliJ IDEA.
 * User: xianfei
 * Date: 15-10-30
 * Time: 上午9:38
 * To change this template use File | Settings | File Templates.
 */
@Controller
@RequestMapping("/valid/userinfo")
public class userInfoValidController {

    @Autowired
    private UserService userService;

    @RequestMapping(value = "username", method = RequestMethod.POST)
    @ResponseBody
    public boolean validUsername(String username) {
        User user = SecurityUtil.currentUser();
        UserInfo find = userService.findUserInfoByUser(user);
        UserInfo userInfo = userService.findUserInfoByUsername(username, find.guid());
        if (userInfo != null) {
            return false;
        }
        return true;
    }

    @RequestMapping(value = "realname", method = RequestMethod.POST)
    @ResponseBody
    public boolean validRealName(String realName) {
        return UserInfoAjaxValid.realName(realName);
    }

    @RequestMapping(value = "email", method = RequestMethod.POST)
    @ResponseBody
    public boolean validEmail(String email) {
        return UserInfoAjaxValid.email(email);
    }

    @RequestMapping(value = "idcard", method = RequestMethod.POST)
    @ResponseBody
    public boolean validIdCard(String idCard) {
        return UserInfoAjaxValid.idCard(idCard);
    }

}
